package com.jing21.learn.fs.service;

import com.aliyuncs.sts.model.v20150401.AssumeRoleResponse;
import com.jing21.learn.fs.dao.FileSecurityDAO;
import com.jing21.learn.fs.util.PolicyUtilly;
import org.springframework.beans.factory.annotation.Autowired;

import javax.inject.Named;

/**
 * Create By zhengjing on 2017/11/7 16:31
 */
@Named
public class FileSecurityService {

    @Autowired
    FileSecurityDAO fileSecurityDAO;

    @Autowired
    PolicyUtilly utilly;

    public AssumeRoleResponse.Credentials credentials(String username) {

        String path = String.format("/user/%s/", username);
        String policy = utilly.staticRead(path);

        return fileSecurityDAO.assumeRole(username, policy);
    }

}
